package org.hackystat.ui.projectviewer.gwt.server.etl;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeSet;

import org.hackystat.telemetry.service.resource.chart.jaxb.TelemetryStream;

/**
 * Encapsulates time series.
 * 
 * @author Pavel Senin.
 * 
 */
public class SeriesDataSet {

  /**
   * The storage.
   */
  private HashMap<String, Series> series;

  /**
   * Constructor, initializes the storage.
   */
  public SeriesDataSet() {
    this.series = new HashMap<String, Series>();
  }

  /**
   * Puts new series into the storage.
   * 
   * @param sName The series name.
   * @param sData The series to store.
   */
  public void put(String sName, TelemetryStream sData) {
    this.series.put(sName, new Series(sData));
  }

  /**
   * Reports the time axis used for this series collection.
   * 
   * @return The time axis.
   */
  public TreeSet<Date> getTimeAxis() {
    if (this.series.isEmpty()) {
      return null;
    }
    else {
      TreeSet<Date> res = new TreeSet<Date>();
      Iterator<String> itr = this.series.keySet().iterator();
      Series s = this.series.get(itr.next());
      res.addAll(s.getSeries().keySet());
      return res;
    }
  }

  /**
   * Reports stored series.
   * 
   * @return The Stored series.
   */
  public HashMap<String, Series> getSeries() {
    return this.series;
  }

}
